<template>
	<div class="content">
		<div class="clear">
			<Form inline class="fl">
				<Input type="text" placeholder="请输入收益人ID" class="w200 m-r10" v-model.trim="uuid"/>
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd HH:mm:ss" @on-change="getTime">
				</DatePicker>
				<Button type="primary" v-on:click="ifGetQuery">查询</Button>
			</Form>
		</div>
		<fieldset>
			<legend>汇总</legend>
			<div>
				<table>
					<tbody>
						<tr>
							<td>累计间接分享收益：
								<span class="blue" v-text="num == null ? 0 : num">0</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</fieldset>
		<Button class="daochu" type="primary" size="large" @click="exportData">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
		<Table stripe :columns="columns" ref="table" :data='list'></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="cuctGetQuery"></Page>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				list: [], // 间接分享收益列表数据
				num: '', // 累计间接分享收益
				info: null, // 总条数
				page: 1, // 页数
				pageSize: 20, // 每页多少条
				dataValue: [], // 时间段值
				uuid: '', // 用户 ID
				columns: [{
						title: '节点个人ID',
						align: 'center',
						key: 'provideUuid'
					},
					{
						title: '节点用户手机号码',
						align: 'center',
						key: 'providePhone',
						render: (h, params) => {
							return h('div', params.row.providePhone == null ? '#' : params.row.providePhone)
						}
					},
					{
						title: '收益人个人ID',
						align: 'center',
						key: 'benefitUuid'
					},
					{
						title: '收益人手机号码',
						align: 'center',
						key: 'benefitPhone',
						render: (h, params) => {
							return h('div', params.row.benefitPhone == null ? '#' : params.row.benefitPhone)
						}
					},
					{
						title: '推荐收益比例',
						align: 'center',
						key: 'rate'
					},
					{
						title: '收益数量',
						align: 'center',
						key: 'num'
					},
					{
						title: '收益时间',
						align: 'center',
						key: 'crateTime',
						sortable: true
					}
				]
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			})
			this.getQuery(); // 查询间接分享收益
		},
		methods: {
			exportData() {
				this.$refs.table.exportCsv({
					filename: '间接分享收益'
				})
			},
			// 处理时间段时间格式
			getTime(daterange) {
				this.dataValue = daterange
			},
			getQuery() { // 查询间接分享收益
				let token = localStorage.getItem("mytoken");
				let params = this.qs.stringify({
					pn: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					startTime: '2000-12-30 00:00:00', // 起始日期
					endTime: '2200-12-30 00:00:00' // 结束日期
				})
				this.axios.post('statistical/earnings', params, {
					headers: {
						Authorization: "bearer " + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.list = res.data.data.data;
						this.info = res.data.data.total;
						this.num = res.data.data.netDetail;
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem("mytoken");
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			cuctGetQuery(page) { // 分页查询间接分享收益
				let token = localStorage.getItem("mytoken");
				let params = this.qs.stringify({
					pn: page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					startTime: '2000-12-30 00:00:00', // 起始日期
					endTime: '2200-12-30 00:00:00' // 结束日期
				})
				this.axios.post('statistical/earnings', params, {
					headers: {
						Authorization: "bearer " + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.list = res.data.data.data;
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem("mytoken");
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			ifGetQuery() { // 条件查询间接分享收益
				let token = localStorage.getItem("mytoken");
				let params = this.qs.stringify({
					pn: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.uuid, // 用户 ID
					startTime: this.dataValue[0] == '' ? '2000-12-30 00:00:00' : this.dataValue[0], // 起始日期
					endTime: this.dataValue[1] == '' ? '2200-12-30 00:00:00' : this.dataValue[1] // 结束日期
				})
				this.axios.post('statistical/earnings', params, {
					headers: {
						Authorization: "bearer " + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.list = res.data.data.data;
						this.info = res.data.data.total;
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem("mytoken");
						this.$router.push({
							name: 'login'
						})
					}
				})
			}
		}
	}
</script>